package com.fndsoft.police.xuancheng.ui.adapter;

import java.util.ArrayList;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.fndsoft.police.xuancheng.R;
import com.fndsoft.police.xuancheng.domain.ui.CommonFormRowDomain;
import com.fndsoft.police.xuancheng.ui.adapter.holder.CommonFormRowHolder;
import com.fndsoft.police.xuancheng.util.ViewUtil;

/**
 * 通用Form列表适配器
 * 
 * @author LiangXiangJu
 * @creationTime 2014-7-19 下午4:07:26
 * @version
 */
public class CommonFormAdapter extends BaseAdapter {
	private ArrayList<CommonFormRowDomain> rowDomains;
	private Object dataModel;
	private boolean isRead;

	public CommonFormAdapter(ArrayList<CommonFormRowDomain> rowDomains,
			Object dataModel, boolean isRead) {
		super();
		this.rowDomains = rowDomains;
		this.dataModel = dataModel;
		this.isRead = isRead;
	}

	@Override
	public int getCount() {
		return rowDomains.size();
	}

	@Override
	public Object getItem(int arg0) {
		return rowDomains.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		CommonFormRowHolder holder = null;
		if (null == convertView) {
			convertView = ViewUtil.buildView(R.layout.common_form_row);
			holder = new CommonFormRowHolder(convertView, dataModel, isRead);
		} else {
			holder = (CommonFormRowHolder) convertView.getTag();
		}
		holder.fillData(arg0, (CommonFormRowDomain) getItem(arg0), convertView);
		return convertView;
	}

}
